# 数据标注
import argparse
from typing import Dict
from apps.dhlp.dxd_data_v1 import DxdDataV1

class DataLabel(object):
    def __init__(self):
        self.name = 'apps.dhlp.data_label.DataLabel'

    @staticmethod
    def startup(params:Dict = {}) -> None:
        DataLabel.prepare_Xs()

    @staticmethod
    def prepare_Xs() -> None:
        rec_db, dev_recs, raw_datas = DxdDataV1.load_raw_datas(params={})
        # 1. 找到记录数最多的设备
        did = DxdDataV1.get_max_recs_dev(dev_recs=dev_recs)
        # 2. 找到该设备所有记录
        tls_recs, tls_labels = DxdDataV1.get_recs(did=did, dev_recs=dev_recs, raw_datas=raw_datas)
        norm_recs, norm_labels = DxdDataV1.generate_norm_recs(tls_recs)
        recs = tls_recs + norm_recs
        labels = tls_labels + norm_labels
        # 随机取出10%作为测试数据，90%作为训练数据
        train_datas, train_labels, test_datas, test_labels = DxdDataV1.split_train_test(recs=recs, labels=labels)
        print(f'train_datas: {type(train_datas[0])}; train_labels: {type(train_labels)};')

def main(params:Dict = {}) -> None:
    DataLabel.startup(params=params)

def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--run_mode', action='store',
        type=int, default=1, dest='run_mode',
        help='run mode'
    )
    return parser.parse_args()

if '__main__' == __name__:
    args = parse_args()
    params = vars(args)
    main(params=params)
